from flask import Blueprint, request
from flask_cors import CORS
from services.fxbaogao import (
    get_daily_fxbaogao_hotspot_from_db,
    get_weekly_fxbaogao_hotspot_from_db,
    get_monthly_fxbaogao_hotspot_from_db,
)

from blueprints.utils import response_error, response_success, is_page_out_of_bounds

fxbaogao_bp = Blueprint("fxbaogao", __name__, url_prefix="/fxbaogao")

CORS(
    fxbaogao_bp, resources={r"/*": {"origins": "http://localhost:5173", "methods": ["GET"], "supports_credentials": True}}
)


@fxbaogao_bp.route("/daily", methods=["GET"])
def get_fxbaogao_hotspot_day():
    """
    获取发现报告日榜数据

    测试地址：http://127.0.0.1:5000/fxbaogao/daily
    """
    # 调用服务层函数获取数据
    result = get_daily_fxbaogao_hotspot_from_db()
    result = [hotspot.to_dict() for hotspot in result]
    return response_success(result)


@fxbaogao_bp.route("/weekly", methods=["GET"])
def get_fxbaogao_hotspot_week():
    """
    获取发现报告周榜数据

    测试地址：http://127.0.0.1:5000/fxbaogao/weekly
    """
    # 调用服务层函数获取数据
    result = get_weekly_fxbaogao_hotspot_from_db()
    result = [hotspot.to_dict() for hotspot in result]
    return response_success(result)


@fxbaogao_bp.route("/monthly", methods=["GET"])
def get_fxbaogao_hotspot_month():
    """
    获取发现报告月榜数据

    测试地址：http://127.0.0.1:5000/fxbaogao/monthly
    """
    # 调用服务层函数获取数据
    result = get_monthly_fxbaogao_hotspot_from_db()
    result = [hotspot.to_dict() for hotspot in result]
    return response_success(result)

